//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "CappedFlooredYoYInflationCoupon.h"
using namespace Cephei::QL::Cashflows;
#include <gen/QL/Indexes/YoYInflationIndex.h>
#include <gen/QL/Times/Period.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/Cashflows/YoYInflationCoupon.h>
#include <gen/QL/Cashflows/YoYInflationCouponPricer.h>
#include <gen/QL/Indexes/InflationIndex.h>
#include <gen/QL/Termstructures/YieldTermStructure.h>
#include <gen/QL/Cashflows/InflationCouponPricer.h>
using namespace Cephei::QL::Indexes;
using namespace Cephei::QL::Times;
using namespace Cephei::QL::Termstructures;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::CCappedFlooredYoYInflationCoupon (DateTime paymentDate, Double nominal, DateTime startDate, DateTime endDate, UInt32 fixingDays, Cephei::QL::Indexes::IYoYInflationIndex^ index, Cephei::QL::Times::IPeriod^ observationLag, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<Double>^ gearing, Microsoft::FSharp::Core::FSharpOption<Double>^ spread, Microsoft::FSharp::Core::FSharpOption<Double>^ cap, Microsoft::FSharp::Core::FSharpOption<Double>^ floor, Microsoft::FSharp::Core::FSharpOption<DateTime>^ refPeriodStart, Microsoft::FSharp::Core::FSharpOption<DateTime>^ refPeriodEnd, Cephei::QL::Cashflows::IYoYInflationCouponPricer^ QL_Pricer) : CYoYInflationCoupon(CCappedFlooredYoYInflationCoupon::typeid)
{
    CYoYInflationIndex^ _Cindex;
    CPeriod^ _CobservationLag;
    CDayCounter^ _CdayCounter;
    try
    {
#ifdef HANDLE
        _phCappedFlooredYoYInflationCoupon = NULL;
#endif
        QuantLib::Date _paymentDate = (QuantLib::Date)ValueHelper::Convert (paymentDate);
        QuantLib::Real _nominal = (QuantLib::Real)ValueHelper::Convert (nominal);
        QuantLib::Date _startDate = (QuantLib::Date)ValueHelper::Convert (startDate);
        QuantLib::Date _endDate = (QuantLib::Date)ValueHelper::Convert (endDate);
        QuantLib::Natural _fixingDays = (QuantLib::Natural)ValueHelper::Convert (fixingDays);
        _Cindex = safe_cast<CYoYInflationIndex^> (index);
        _Cindex->Lock();
        boost::shared_ptr<QuantLib::YoYInflationIndex>& _index = static_cast<boost::shared_ptr<QuantLib::YoYInflationIndex>&> (_Cindex->GetShared ()); 
        _CobservationLag = safe_cast<CPeriod^> (observationLag);
        _CobservationLag->Lock();
        QuantLib::Period& _observationLag = static_cast<QuantLib::Period&> (_CobservationLag->GetReference ()); 
        _CdayCounter = safe_cast<CDayCounter^> (dayCounter);
        _CdayCounter->Lock();
        QuantLib::DayCounter& _dayCounter = static_cast<QuantLib::DayCounter&> (_CdayCounter->GetReference ()); 
        QuantLib::Real _gearing = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (gearing) ? (QuantLib::Real)ValueHelper::Convert (gearing->Value) : 1.0); //4
        QuantLib::Spread _spread = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (spread) ? (QuantLib::Spread)ValueHelper::Convert (spread->Value) : 0.0); //4
        QuantLib::Rate _cap = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (cap) ? (QuantLib::Rate)ValueHelper::Convert (cap->Value) : Null<QuantLib::Rate>()); //4
        QuantLib::Rate _floor = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (floor) ? (QuantLib::Rate)ValueHelper::Convert (floor->Value) : Null<QuantLib::Rate>()); //4
        QuantLib::Date _refPeriodStart = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (refPeriodStart) ? (QuantLib::Date)ValueHelper::Convert (refPeriodStart->Value) : QuantLib::Date()); //4
        QuantLib::Date _refPeriodEnd = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (refPeriodEnd) ? (QuantLib::Date)ValueHelper::Convert (refPeriodEnd->Value) : QuantLib::Date()); //4
        _ppCappedFlooredYoYInflationCoupon = new boost::shared_ptr<QuantLib::CappedFlooredYoYInflationCoupon> (new QuantLib::CappedFlooredYoYInflationCoupon ( _paymentDate,  _nominal,  _startDate,  _endDate,  _fixingDays,  _index,  _observationLag,  _dayCounter,  _gearing,  _spread,  _cap,  _floor,  _refPeriodStart,  _refPeriodEnd ));
        CYoYInflationCouponPricer^ _CQL_Pricer = safe_cast<CYoYInflationCouponPricer^> (QL_Pricer);
        boost::shared_ptr<QuantLib::YoYInflationCouponPricer>& _QL_Pricer = static_cast<boost::shared_ptr<QuantLib::YoYInflationCouponPricer>&> (_CQL_Pricer->GetShared ());
        (*_ppCappedFlooredYoYInflationCoupon)->setPricer (_QL_Pricer);
        SetYoYInflationCoupon (boost::dynamic_pointer_cast<QuantLib::YoYInflationCoupon> (*_ppCappedFlooredYoYInflationCoupon));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cindex != nullptr) _Cindex->Unlock();
        if (_CobservationLag != nullptr) _CobservationLag->Unlock();
        if (_CdayCounter != nullptr) _CdayCounter->Unlock();
    }
}
Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::CCappedFlooredYoYInflationCoupon (Cephei::QL::Cashflows::IYoYInflationCoupon^ underlying, Microsoft::FSharp::Core::FSharpOption<Double>^ cap, Microsoft::FSharp::Core::FSharpOption<Double>^ floor, Cephei::QL::Cashflows::IYoYInflationCouponPricer^ QL_Pricer) : CYoYInflationCoupon(CCappedFlooredYoYInflationCoupon::typeid)
{
    CYoYInflationCoupon^ _Cunderlying;
    try
    {
#ifdef HANDLE
        _phCappedFlooredYoYInflationCoupon = NULL;
#endif
        _Cunderlying = safe_cast<CYoYInflationCoupon^> (underlying);
        _Cunderlying->Lock();
        boost::shared_ptr<QuantLib::YoYInflationCoupon>& _underlying = static_cast<boost::shared_ptr<QuantLib::YoYInflationCoupon>&> (_Cunderlying->GetShared ()); 
        QuantLib::Rate _cap = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (cap) ? (QuantLib::Rate)ValueHelper::Convert (cap->Value) : Null<QuantLib::Rate>()); //4
        QuantLib::Rate _floor = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (floor) ? (QuantLib::Rate)ValueHelper::Convert (floor->Value) : Null<QuantLib::Rate>()); //4
        _ppCappedFlooredYoYInflationCoupon = new boost::shared_ptr<QuantLib::CappedFlooredYoYInflationCoupon> (new QuantLib::CappedFlooredYoYInflationCoupon ( _underlying,  _cap,  _floor ));
        CYoYInflationCouponPricer^ _CQL_Pricer = safe_cast<CYoYInflationCouponPricer^> (QL_Pricer);
        boost::shared_ptr<QuantLib::YoYInflationCouponPricer>& _QL_Pricer = static_cast<boost::shared_ptr<QuantLib::YoYInflationCouponPricer>&> (_CQL_Pricer->GetShared ());
        (*_ppCappedFlooredYoYInflationCoupon)->setPricer (_QL_Pricer);
        SetYoYInflationCoupon (boost::dynamic_pointer_cast<QuantLib::YoYInflationCoupon> (*_ppCappedFlooredYoYInflationCoupon));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cunderlying != nullptr) _Cunderlying->Unlock();
    }
}
Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::CCappedFlooredYoYInflationCoupon (boost::shared_ptr<QuantLib::CappedFlooredYoYInflationCoupon>& childNative, Object^ owner) : CYoYInflationCoupon(CCappedFlooredYoYInflationCoupon::typeid)
{
#ifdef HANDLE
	_phCappedFlooredYoYInflationCoupon = NULL;
#endif
	_ppCappedFlooredYoYInflationCoupon = &childNative;
    _ppYoYInflationCoupon = new boost::shared_ptr<QuantLib::YoYInflationCoupon> (boost::dynamic_pointer_cast<QuantLib::YoYInflationCoupon> (*_ppCappedFlooredYoYInflationCoupon));
}
Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::CCappedFlooredYoYInflationCoupon (QuantLib::CappedFlooredYoYInflationCoupon& childNative, Object^ owner) : CYoYInflationCoupon(CCappedFlooredYoYInflationCoupon::typeid)
{
#ifdef HANDLE
	_phCappedFlooredYoYInflationCoupon = NULL;
#endif
	_ppCappedFlooredYoYInflationCoupon = new boost::shared_ptr<QuantLib::CappedFlooredYoYInflationCoupon> (&childNative);
    _ppYoYInflationCoupon = new boost::shared_ptr<QuantLib::YoYInflationCoupon> (boost::dynamic_pointer_cast<QuantLib::YoYInflationCoupon> (*_ppCappedFlooredYoYInflationCoupon));
    _CappedFlooredYoYInflationCouponOwner = owner;
    _YoYInflationCouponOwner = owner;
}

Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::CCappedFlooredYoYInflationCoupon (CCappedFlooredYoYInflationCoupon^ copy) : CYoYInflationCoupon(CCappedFlooredYoYInflationCoupon::typeid)
{
#ifdef HANDLE
	_phCappedFlooredYoYInflationCoupon = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppCappedFlooredYoYInflationCoupon = new boost::shared_ptr<QuantLib::CappedFlooredYoYInflationCoupon> (copy->GetShared());
        _ppYoYInflationCoupon = new boost::shared_ptr<QuantLib::YoYInflationCoupon> (boost::dynamic_pointer_cast<QuantLib::YoYInflationCoupon> (*_ppCappedFlooredYoYInflationCoupon));
    }
}
Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::CCappedFlooredYoYInflationCoupon (System::Type^ t) : CYoYInflationCoupon(CCappedFlooredYoYInflationCoupon::typeid)
{
#ifdef HANDLE
	_phCappedFlooredYoYInflationCoupon = NULL;
#endif
	if (!t->IsSubclassOf(CCappedFlooredYoYInflationCoupon::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::CCappedFlooredYoYInflationCoupon (QuantLib::Handle<QuantLib::CappedFlooredYoYInflationCoupon>& childNative, Object^ owner)  : CYoYInflationCoupon(CCappedFlooredYoYInflationCoupon::typeid)
{
	_phCappedFlooredYoYInflationCoupon = &childNative;
	_ppCappedFlooredYoYInflationCoupon = &static_cast<boost::shared_ptr<QuantLib::CappedFlooredYoYInflationCoupon>>(childNative.currentLink());
    _ppYoYInflationCoupon = new boost::shared_ptr<QuantLib::YoYInflationCoupon> (boost::dynamic_pointer_cast<QuantLib::YoYInflationCoupon> (*_ppCappedFlooredYoYInflationCoupon));
    _CappedFlooredYoYInflationCouponOwner = owner;
}
Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::CCappedFlooredYoYInflationCoupon (QuantLib::Handle<QuantLib::CappedFlooredYoYInflationCoupon> childNative)  : CYoYInflationCoupon(CCappedFlooredYoYInflationCoupon::typeid)
{
	_phCappedFlooredYoYInflationCoupon = &childNative;
	_ppCappedFlooredYoYInflationCoupon = &static_cast<boost::shared_ptr<QuantLib::CappedFlooredYoYInflationCoupon>>(childNative.currentLink());
    _ppYoYInflationCoupon = new boost::shared_ptr<QuantLib::YoYInflationCoupon> (boost::dynamic_pointer_cast<QuantLib::YoYInflationCoupon> (*_ppCappedFlooredYoYInflationCoupon));
}
#endif
#ifdef STRUCT
Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::CCappedFlooredYoYInflationCoupon (QuantLib::CappedFlooredYoYInflationCoupon childNative)  : CYoYInflationCoupon(CCappedFlooredYoYInflationCoupon::typeid)
{
#ifdef HANDLE
	_phCappedFlooredYoYInflationCoupon = NULL;
#endif
	_ppCappedFlooredYoYInflationCoupon = new boost::shared_ptr<QuantLib::CappedFlooredYoYInflationCoupon> (new QuantLib::CappedFlooredYoYInflationCoupon (childNative));
    _ppYoYInflationCoupon = new boost::shared_ptr<QuantLib::YoYInflationCoupon> (boost::dynamic_pointer_cast<QuantLib::YoYInflationCoupon> (*_ppCappedFlooredYoYInflationCoupon));
}
#endif

Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::~CCappedFlooredYoYInflationCoupon ()
{
    if (_ppCappedFlooredYoYInflationCoupon != NULL)
    {
	    delete _ppCappedFlooredYoYInflationCoupon;
        _ppCappedFlooredYoYInflationCoupon = NULL;
    }
}
Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::!CCappedFlooredYoYInflationCoupon ()
{
    if (_ppCappedFlooredYoYInflationCoupon != NULL)
    {
	    delete _ppCappedFlooredYoYInflationCoupon;
    }
}
QuantLib::CappedFlooredYoYInflationCoupon& Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::GetReference ()
{
    if (_ppCappedFlooredYoYInflationCoupon == NULL) throw gcnew NativeNullException ();
	return **_ppCappedFlooredYoYInflationCoupon;
}
boost::shared_ptr<QuantLib::CappedFlooredYoYInflationCoupon>& Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::GetShared ()
{
    if (_ppCappedFlooredYoYInflationCoupon == NULL) throw gcnew NativeNullException ();
	return *_ppCappedFlooredYoYInflationCoupon;
}
QuantLib::CappedFlooredYoYInflationCoupon* Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::GetPointer ()
{
    if (_ppCappedFlooredYoYInflationCoupon == NULL) throw gcnew NativeNullException ();
	return &**_ppCappedFlooredYoYInflationCoupon;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::CappedFlooredYoYInflationCoupon>& Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::GetHandle ()
{
	if (_phCappedFlooredYoYInflationCoupon == NULL)
	{
		_phCappedFlooredYoYInflationCoupon = new Handle<QuantLib::CappedFlooredYoYInflationCoupon> (*_ppCappedFlooredYoYInflationCoupon);
	}
	return *_phCappedFlooredYoYInflationCoupon;
}
#endif
bool Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::HasNative () 
{
	return (_ppCappedFlooredYoYInflationCoupon != NULL);
}

Double Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::Cap::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppCappedFlooredYoYInflationCoupon)->cap ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::EffectiveCap::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppCappedFlooredYoYInflationCoupon)->effectiveCap ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::EffectiveFloor::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppCappedFlooredYoYInflationCoupon)->effectiveFloor ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::Floor::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppCappedFlooredYoYInflationCoupon)->floor ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::IsCapped::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppCappedFlooredYoYInflationCoupon)->isCapped ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Boolean Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::IsFloored::get ()
{
    try
    {
    	bool _rv = (bool)(*_ppCappedFlooredYoYInflationCoupon)->isFloored ( );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::Rate::get ()
{
    try
    {
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppCappedFlooredYoYInflationCoupon)->rate ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Cashflows::ICappedFlooredYoYInflationCoupon^ Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::SetPricer (Cephei::QL::Cashflows::IYoYInflationCouponPricer^ pricer)
{
    CYoYInflationCouponPricer^ _Cpricer;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _Cpricer = safe_cast<CYoYInflationCouponPricer^> (pricer);
        _Cpricer->Lock();
        boost::shared_ptr<QuantLib::YoYInflationCouponPricer>& _pricer = static_cast<boost::shared_ptr<QuantLib::YoYInflationCouponPricer>&> (_Cpricer->GetShared ()); 
    	(*_ppCappedFlooredYoYInflationCoupon)->setPricer ( _pricer );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cpricer != nullptr) _Cpricer->Unlock();
    }
}
Cephei::QL::Cashflows::ICappedFlooredYoYInflationCoupon^ Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon::Update::get ()
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
    	(*_ppCappedFlooredYoYInflationCoupon)->update ( );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Cashflows::ICappedFlooredYoYInflationCoupon^ Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon_Factory::Create (DateTime paymentDate, Double nominal, DateTime startDate, DateTime endDate, UInt32 fixingDays, Cephei::QL::Indexes::IYoYInflationIndex^ index, Cephei::QL::Times::IPeriod^ observationLag, Cephei::QL::Times::IDayCounter^ dayCounter, Microsoft::FSharp::Core::FSharpOption<Double>^ gearing, Microsoft::FSharp::Core::FSharpOption<Double>^ spread, Microsoft::FSharp::Core::FSharpOption<Double>^ cap, Microsoft::FSharp::Core::FSharpOption<Double>^ floor, Microsoft::FSharp::Core::FSharpOption<DateTime>^ refPeriodStart, Microsoft::FSharp::Core::FSharpOption<DateTime>^ refPeriodEnd, Cephei::QL::Cashflows::IYoYInflationCouponPricer^ QL_Pricer)
{
    return gcnew CCappedFlooredYoYInflationCoupon ( paymentDate,  nominal,  startDate,  endDate,  fixingDays,  index,  observationLag,  dayCounter,  gearing,  spread,  cap,  floor,  refPeriodStart,  refPeriodEnd,  QL_Pricer);
}
Cephei::QL::Cashflows::ICappedFlooredYoYInflationCoupon^ Cephei::QL::Cashflows::CCappedFlooredYoYInflationCoupon_Factory::Create (Cephei::QL::Cashflows::IYoYInflationCoupon^ underlying, Microsoft::FSharp::Core::FSharpOption<Double>^ cap, Microsoft::FSharp::Core::FSharpOption<Double>^ floor, Cephei::QL::Cashflows::IYoYInflationCouponPricer^ QL_Pricer)
{
    return gcnew CCappedFlooredYoYInflationCoupon ( underlying,  cap,  floor,  QL_Pricer);
}
